<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" id="vp" content="width=device-width, initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <title>童圈</title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <link href="../../css/mui.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="../../src/style.css">
    <link rel="stylesheet" href="../../src/iconfont/iconfont.css">
    <style>
        .swiper-slide img {
            width: 100%;
            height: auto;
        }
        
        .swiper-slide {
            background: #ffffff;
        }
        
        .modelShows {
            width: 100%;
            background-color: rgba(255, 255, 255, 0.43);
            position: fixed;
            left: 0px;
            top: 0px;
            z-index: 1111;
        }
        
        .swiper-slide {
            height: auto;
        }
        
        #banner {
            width: 100%;
            height: 6rem;
            margin: 0 auto;
            position: relative;
            top: 0;
            left: 0;
        }
        
        .operate span {
            font-size: 20px;
            width: 33.33%;
            margin-left: 10px;
        }
        
        .icon-favorfill {
            color: #ff8383;
        }
        
        .icon-likefill {
            color: #ff8383;
        }
        
        .icon-more {
            width: auto!important;
        }
        
        .newMsgTheme {
            position: relative;
            width: 100px;
            height: 28px;
            padding-top: 10px;
            background: #5d5d5d;
            border-radius: 3px;
            margin-left: 10px;
            word-break: break-word;
            color: white;
            padding: 5px;
            line-height: 18px;
            bottom: 5px;
            right: 8px;
            display: flex;
            flex-wrap: nowrap;
        }
        
        .newMsgTheme::after {
            content: "";
            display: block;
            position: absolute;
            width: 0;
            height: 0;
            border: 8px solid transparent;
            border-right-color: #5d5d5d;
            top: 6px;
            right: -14px;
            transform: rotate(180deg);
        }
        
        #children .redmsgbox {
            background-color: aliceblue;
            border: none;
        }
        
        #children .redmsgbox img {
            width: 30px;
            display: inline-block!important;
            padding: 5px 0;
            float: left;
        }
        
        #children .redmsgbox span {
            line-height: 40px;
            padding-left: 5px;
        }
    </style>
</head>

<body>
    <div id="children">
        <div @click.stop="closeModelShows" class="modelShows" v-show="modelShows" :style="{height:winHeight+'px'}">

        </div>
        <!-- <ul>
            <li>
                <a href="#">拍视频</a>
            </li>
            <li>
                <a href="#">发图片</a>
            </li>
        </ul> -->

        <div @click.stop="closeModel" v-show="modelShow" class="msgModel" :style="{height:winHeight+'px'}"></div>
        <div v-show="modelShow" class="msgInput">
            <input v-model="msgValue" type="text" placeholder="评论">
            <a href="#" @click.stop="put">{{msgbtntext}}</a>
        </div>
        <div class="newHeader">
            <!-- @tap="sendMsg()" -->
            <div class="sendmsg" id="sendmsg">
                <font class="mui-icon mui-icon-camera"></font>
            </div>
        </div>

        <!--banner-->
        <div id="banner">
            <div class="swiper-container">
                <div class="swiper-wrapper"></div>
                <div class="pagination"></div>
            </div>
        </div>
        <!--未读消息-->
        <div id="noreadmsg" class="noreadmsg" @tap="newmsgchange()">
            <div class="redmsgbox">
                <img :src="newmsg.pic" />
                <span>您有{{newmsg.count}}条未读消息</span>
            </div>
        </div>
        <!--消息列表-->
        <div class="list-frame" id="list">
            <ul class="list-info">
                <template v-for="(item,index) in items" :key="index">
						<li class="list-info-li">
							<div class="main clearfix">
								<div :style="{backgroundImage:'url(' + item.member_avatar + ')'}" class="people-l fl"></div>
								<!--img :src="item.member_avatar" class="people-l fl" /-->
								<div class="list-info-li-r fl">
									<div class="name posir">
										<div class="name-text">{{item.member_name}}</div>
									</div>
									<!--消息内容-->
									<div class="text-info" id="text-info">
										<p class="text overhide word-long fold">{{item.content}}</p>
										<p class="all" v-if="item.content.length>95" @click="handleFold($event)" onclick="javascript:this.innerHTML=(this.innerHTML=='全文'?'收起':'全文')">全文</p>
									</div>
									<!--1.单图-->
									<div class="list-info-pic" v-if="item.type==1">
										<img :src="item.message_image" class="imgWidth" @tap="previewimg(item.message_image,0)" />
									</div>
									<!--2.多图-->
									<div class="list-info-pic clearfix" v-if="item.type==2">
										<div :style="{backgroundImage:'url(' + pic + ')'}" class="list-ip-img2 list-info-picBackground fl" v-for="(pic,index) in item.message_image" @tap="previewimg(item.message_image,index)"></div>
									</div>
									<!--3.视频-->
									<div class="clearfix clearfixvideo" v-if="item.type==3">
										<video :src="item.video" class="videoWidth" :poster="item.videoimg" type="video/mp4"></video>
										<div class="playbtn"><img src="../../images/play.png" /></div>
									</div>
									<!--4.图文-->
									<div class="list-info-li-tuwen clearfix" v-if="item.type==4" @tap="open_detail(item.link,item.title)">
										<div class="list-info-li-tuwenBackground" :style="{backgroundImage:'url(' + item.pic + ')'}"></div>
										<div class="list-info-li-tuwenContent fl">
											<div><span :class="item.title.length>18 ? 'p1' : 'p2' ">{{item.title}}</span></div>
										</div>
									</div>
									<!--5.其他-->
									<div class="list-info-pic clearfix" v-if="item.type==5">
									</div>
									<!--操作按钮-->
									<div class="fabulous clearfix">
										<div class="text fl"><span class="fl">{{item.ftime}}</span><span v-if="item.member_id==item.uid" class="trash fl" @click="delmsg(item,index)" />删除</span>
										</div>
										<div class="operate fr" style="display: flex;flex-wrap: nowrap">
                                            <div class="newMsgTheme" v-show="item.show">
                                                    <span :data-index="index" class="iconfont" @click="setupvote($event,item)" v-bind:class="[item.upvote_status==0?'icon-like':'icon-likefill']"></span>
                                                    <span :data-index="index" class="iconfont icon-comment" @click="commenta($event,item)" ></span>
                                                    <span :data-index="index" class="iconfont" @click="savetofav($event,item)" v-bind:class="[item.coll==0?'icon-favor':'icon-favorfill']"></span>
                                            </div>
                                            <span class="iconfont icon-more" @click.stop="get" :data-index="index"></span>
										</div>
									</div>
									<div class="pinglun">
										<div class="dianzan" v-if="item.upvote_count!=0">
											<img src="../../images/icon/xin_3.png" class="xintu fl" />
											<div class="zannameBox">
												<span v-for="(zan,index) in item.upvote">{{zan.member_name}}<span v-if="item.upvote_count>5 ? index<4 : index<item.upvote_count-1">,</span></span>
											</div>

											<!-- <div class="clear"></div> -->
											<!-- <div class="zancounta" v-if="item.upvote_count>5"  @tap="commentContent(item)">...等{{item.upvote_count}}人觉得很赞</div>  -->
											<div class="zancounta" style="font-size: 12px;" @tap="commentContent(item)">...等{{item.upvote_count}}人觉得很赞</div>
											<!-- <div class="clear"></div> -->
										</div>

										<div class="pinglunCo">
											<div class="pinglunBoxb" v-for="(comment,index) in item.comment" v-if="index<5">
												<div>
													<span class="pinglunname">{{comment.member_name}}</span><span class="maohao">:</span><span class="pinglunCoten">{{comment.comment_content}}</span><span class="delComment" @tap="delcomment(item,comment,event)">删除</span>
													<div class="clear"></div>
												</div>
											</div>
										</div>
										<div v-if="item.comment_count>5" class="morez" @tap="commentContent(item)">更多...</div>
										<div class="clear"></div>
									</div>
								</div>
						</li>
					</template>
            </ul>
        </div>
    </div>
    <!--轮播banner-->
    <script src="../../js/mui.js"></script>
    <script src="../../js/idangerous.swiper.min.js"></script>
    <script src="../../js/vue.min.js"></script>
    <script src="../../js/app.js"></script>
    <script src="../../js/iconfont.js"></script>
    <script type="text/javascript" src="../../js/jquery-1.8.3.min.js"></script>
    <script>
        $(function() {
            console.log(jQuery('.newMsgTheme'))
            console.log("asdf")
        })
        var state = "";
        var operateStatus = 1; //防止点赞收藏等操作太快
        var currItem;
        //停止播放
        function pause() {
            for (var i = 0; i < $('.videoWidth').length; i++) {
                $('.videoWidth')[i].pause();
                $('.playbtn')[i].style.display = 'block';
            }
        }

        //处理返回键
        var backButtonPress = 0;
        var old_back = mui.back;
        mui.back = function(event) {
            var adWebview = plus.webview.getWebviewById('ad_detail');
            if (adWebview) {
                adWebview.close();
            } else {
                backButtonPress++;
                if (backButtonPress > 1) {
                    plus.runtime.quit();
                } else {
                    plus.nativeUI.toast('再按一次退出应用');
                }
                setTimeout(function() {
                    backButtonPress = 0;
                }, 1000);
                return false;
            }
        };



        mui.plusReady(function() {
            if (window.plus && plus.networkinfo.getCurrentType() === plus.networkinfo.CONNECTION_NONE) {
                plus.nativeUI.alert('请打开网络后再次使用', function() {
                    plus.runtime.quit();
                });

            }

            var doms = document.getElementById('sendmsg')
            doms.addEventListener("longtap", function() {
                // console.log("你正在向左滑动");
                mui.openWindowWithTitle({
                    url: './sendvideo.html',
                    id: 'sendmoment',
                    preload: true,
                    extras: {
                        msgtype: '4',
                    },
                    show: {
                        aniShow: 'pop-in',
                        autoShow: true
                    },
                    waiting: {
                        autoShow: true
                    }
                })
            });
            doms.addEventListener("tap", function() {
                mui.openWindowWithTitle({
                    url: './sendmsg.html',
                    id: 'sendmoment',
                    preload: true,
                    extras: {
                        msgtype: '4',
                    },
                    show: {
                        aniShow: 'pop-in',
                        autoShow: true
                    },
                    waiting: {
                        autoShow: true
                    }
                })
            })
            state = app.getState();
            memberToken = state.memberToken;
            data = {
                uid: state.userid,
                memberToken: memberToken
            };
            mui.post(Apiurl+'index/message_list', data, function(data) {
                children.banners = data.banner;
                var bannerHtml = "";
                for (var i = 0; i < data.banner.length; i++) {
                    bannerHtml += "<div class=\"swiper-slide\" onclick=\"open_detail('" + data.banner[i].banner_url + "','" + data.banner[i].banner_title + "');\"><img src='" + data.banner[i].banner_pic + "'></div>";
                }
                $(".swiper-wrapper").html(bannerHtml);
                var mySwiper = new Swiper('.swiper-container', {
                    loop: true,
                    pagination: '.pagination',
                    paginationClickable: true,
                    moveStartThreshold: 100,
                    centeredSlides: true,
                    autoplay: 3500,
                    autoplayDisableOnInteraction: false
                })
            }, 'json');
            plus.webview.currentWebview().setStyle({
                'scrollIndicator': 'none'
            });
            mui('#list').on('tap', '.playbtn', function() {
                pause();
                this.previousElementSibling.play();
                this.previousElementSibling.webkitRequestFullScreen()
                this.style.display = 'none';
                this.previousElementSibling.addEventListener('ended', function() {
                    this.nextElementSibling.style.display = 'block';
                })
            })

            mui('#list').on('tap', '.videoWidth', function() {
                this.pause();
                this.nextElementSibling.style.display = 'block';
            })
            plus.webview.currentWebview().setStyle({
                softinputMode: "adjustResize"
            });
            //pulldownRefresh();

        });

        //mui初始化，配置下拉刷新
        mui.init({
            gestureConfig: {
                longtap: true
            },
            pullRefresh: {
                container: '#list',
                down: {
                    style: 'circle',
                    offset: '220px',
                    auto: true,
                    callback: function() {
                        pages = 1;
                        pulldownRefresh(pages)
                    }
                },
                up: {
                    contentrefresh: '正在加载...',
                    callback: function() {
                        pages++;
                        pullupRefresh(pages)
                    }
                }
            }
        });

        Vue.directive('focus', {
            // 当绑定元素插入到 DOM 中。

            inserted: function(el) {
                // 聚焦元素
                el.focus()
            },
            //也可以用update,update就是当页面有操作的时候就触发，比如点击按钮，输入框输入都算。
            //有一个要注意的就是，就是你页面有几个input,比如一个input绑定了v-focus,一个没有绑定。你在没绑定v-focus的input输入时，绑定了v-focus的input就是自动获取焦点，这是个bug.
            //update: function (el) {
            //el.focus()
            //}
        });
        var children = new Vue({
            el: '#children',
            data: {
                banners: [], //顶部banner数据
                items: [], //列表信息流数据
                fold: true,
                clickTf: true,
                activeindex: 0,
                commentcontent: [],
                newmsg: [],
                winHeight: window.innerHeight,
                modelShow: false,
                msgValue: "",
                msgids: "",
                modelShows: false,
                msgbtntext: "发布"
            },

            methods: {
                get(e) {
                    console.log(e.target.dataset.index)
                    $('.newMsgTheme').hide()
                    if (children.items[e.target.dataset.index].show == true) {
                        children.items[e.target.dataset.index].show = false
                    } else {
                        children.items[e.target.dataset.index].show = true
                    }
                    this.$forceUpdate();
                },
                closeModelShows() {
                    children.modelShows = false
                },
                closeModel: function() {
                    children.modelShow = false
                },
                put: function() {
                    console.log("asdf")
                    console.log(children.msgValue)
                    var commentvalue = children.msgValue
                    if (commentvalue.trim() == "") return;
                    if (commentvalue.length > 200) {
                        alert('请评论小于200个字数');
                    } else {
                        this.msgbtntext = "发布中..."
                        mui.post(Apiurl+'index/comment', {
                            uid: state.userid,
                            id: children.msgids,
                            content: children.msgValue,
                            memberToken: memberToken
                        }, function(data) {
                            if (data.status == 200) {
                                plus.nativeUI.toast('评论成功', {
                                    verticalAlign: 'middle'
                                });
                                let dd = {
                                    uid: state.userid,
                                    memberToken: memberToken
                                }
                                mui.post(Apiurl+'index/message_list', dd, function(res) {
                                    console.log(res)
                                    children.items = res.message
                                    children.msgValue = ""
                                    children.modelShow = false
                                }, 'json');
                                this.msgbtntext = "发布"
                            } else if (data.status == 404) {
                                plus.nativeUI.toast('您的输入包含敏感词汇', {

                                    verticalAlign: 'middle'
                                });
                                children.msgValue = ""
                                this.msgbtntext = "发布"
                            } else if (data.status == 405) {
                                plus.nativeUI.toast('评论异常', {
                                    verticalAlign: 'middle'
                                });
                                children.msgValue = ""
                                this.msgbtntext = "发布"

                            }
                        }, 'json')

                    }
                },
                //发布信息
                sendMsg: function() {
                    children.modelShows = true
                        // if (mui.os.plus) {
                        //     var a = [{
                        //         title: "视频"
                        //     }, {
                        //         title: "图片"
                        //     }];
                        //     plus.nativeUI.actionSheet({
                        //         title: "发布类型",
                        //         cancel: "取消",
                        //         buttons: a
                        //     }, function(b) {
                        //         switch (b.index) {
                        //             case 0:
                        //                 break;
                        //             case 1:
                        //                 pause();
                        //                 mui.openWindowWithTitle({
                        //                     url: './sendvideo.html',
                        //                     id: 'sendmoment',
                        //                     preload: true,
                        //                     extras: {
                        //                         msgtype: '4',
                        //                     },
                        //                     show: {
                        //                         aniShow: 'pop-in',
                        //                         autoShow: true
                        //                     },
                        //                     waiting: {
                        //                         autoShow: true
                        //                     }
                        //                 })
                        //                 break;
                        //             case 2:
                        //                 pause();
                        //                 mui.openWindowWithTitle({
                        //                     url: './sendmsg.html',
                        //                     id: 'sendmoment',
                        //                     preload: true,
                        //                     extras: {
                        //                         msgtype: '4',
                        //                     },
                        //                     show: {
                        //                         aniShow: 'pop-in',
                        //                         autoShow: true
                        //                     },
                        //                     waiting: {
                        //                         autoShow: true
                        //                     }
                        //                 })
                        //                 break;
                        //             default:
                        //                 break
                        //         }
                        //     })
                        // }
                },
                newmsgchange: function() {
                    //点击我的未读消息后，清除底部数字提示和顶部提示框
                    document.getElementById('noreadmsg').style.display = 'none';
                    var mainPage = plus.webview.getWebviewById('main');
                    mui.fire(mainPage, 'refreshmymsgnum', {});
                    //设置新页面标题
                    mui.openWindow({
                        url: './mymsg.html',
                        id: 'moments_mymsg',
                        preload: true,
                        show: {
                            aniShow: 'pop-in',
                            autoShow: true
                        },
                        styles: {
                            "render": "always",
                            "popGesture": "hide",
                            "bounce": "vertical",
                            "bounceBackground": "#efeff4",
                            "titleNView": { //详情页原生导航配置
                                backgroundColor: '#fff', //导航栏背景色
                                titleText: '我的新消息', //导航栏标题
                                titleColor: '#000', //文字颜色
                                autoBackButton: true, //自动绘制返回箭头
                                splitLine: { //底部分割线
                                    color: '#DFDFDF'
                                }
                            }
                        },
                        waiting: {
                            autoShow: true
                        }
                    });
                },
                //评论点赞详情
                commentContent: function(item) {
                    pause();
                    titlestyle.titleNView.titleText = "消息详情";
                    mui.openWindow({
                        url: './detail.html',
                        id: 'moments_detail',
                        preload: true,
                        extras: {
                            messageid: item.id
                        },
                        show: {
                            aniShow: 'pop-in',
                            autoShow: true
                        },
                        styles: titlestyle,
                        waiting: {
                            autoShow: true
                        }
                    });
                },
                //删除消息
                delmsg: function(item, index) {
                    var data = {
                        uid: state.userid,
                        message_id: item.id,
                        memberToken: memberToken
                    };
                    that = this;
                    var btnArray = ['否', '是'];
                    mui.confirm('您是否要删除该条信息？', '删除确认', btnArray, function(e) {

                        if (e.index == 1) {
                            mui.post(Apiurl+'index/messagedel', data, function(data) {
                                if (data.status == "200") {
                                    that.items.splice(index, 1);
                                }
                            }, 'json');
                        }
                    })
                },
                commenta: function(e, item) {
                    let _slef = children
                    children.modelShow = true
                    console.log(item.id)
                    children.msgids = item.id
                    console.log("asdf")
                    console.log(e.target.dataset.index)
                    if (children.items[e.target.dataset.index].show == true) {
                        children.items[e.target.dataset.index].show = false
                    } else {
                        children.items[e.target.dataset.index].show = true
                    }
                    this.$forceUpdate();
                    /*document.getElementById('inputBox').style.display = 'block';
                    document.getElementById("inputa").value="";
                    document.getElementById('inputa').focus();
                    currItem = item;*/
                    // titlestyle.titleNView.titleText = "消息详情";

                    // mui.openWindow({
                    //     url: 'detail.html',
                    //     id: 'commentCon',
                    //     preload: true,
                    //     extras: {
                    //         messageid: item.id
                    //     },
                    //     show: {
                    //         aniShow: 'pop-in',
                    //         autoShow: true
                    //     },
                    //     styles: titlestyle,
                    //     waiting: {
                    //         autoShow: true
                    //     }
                    // });
                },
                //删除评论
                delcomment: function(item, comment, event) {
                    console.log();
                    var data = {
                        uid: state.userid,
                        id: comment.comment_id,
                        memberToken: memberToken
                    };
                    that = this;
                    var btnArray = ['否', '是'];
                    mui.confirm('您是否要删除该条评论？', '删除确认', btnArray, function(e) {
                        if (e.index == 1) {
                            mui.post(Apiurl+'index/delcomment', data, function(res) {
                                if (res.status == "200") {
                                    item.comment = res.comment;
                                    item.comment_count = res.comment_count;
                                    item.comment_content = res.comment_ccontent;
                                    plus.nativeUI.toast('删除成功', {
                                        verticalAlign: 'middle'
                                    });
                                }
                            }, 'json');
                        }
                    })
                },
                //图片预览
                previewimg: function(item, index) {
                    var urls = [];
                    item.forEach(function(img) {
                        urls.push(img);
                    });

                    plus.nativeUI.previewImage(urls, {
                        current: index,
                        loop: true,
                        indicator: 'number'
                    });
                },
                //全文/收起
                handleFold: function(e) {
                    if (e.target.previousElementSibling.getAttribute('class') == 'text overhide word-long fold') {
                        e.target.previousElementSibling.setAttribute('class', 'text overhide word-long unfold')
                    } else {
                        e.target.previousElementSibling.setAttribute('class', 'text overhide word-long fold')
                    }

                },
                //点赞
                setupvote: function(e, item) {

                    var data = {
                        uid: state.userid,
                        id: item.id,
                        memberToken: memberToken
                    };
                    if (item.upvote_status == '1') {
                        item.upvote_status = '0';
                        e.srcElement.setAttribute('src', '../../images/icon/upvote_0.png');
                    } else if (item.upvote_status == '0') {
                        item.upvote_status = '1';
                        e.srcElement.setAttribute('src', '../../images/icon/upvote_1.png');

                    }
                    mui.post(Apiurl+'index/upvote', data, function(data) {
                        console.log(JSON.stringify(data));
                        if (data.upvote_status == "0") {
                            item.upvote = data.upvote;
                            item.upvote_count = data.upvote_count;
                        }
                        if (data.upvote_status == "1") {
                            item.upvote = data.upvote;
                            item.upvote_count = data.upvote_count;
                        }
                    }, 'json');

                    console.log(e.target.dataset.index)
                    if (children.items[e.target.dataset.index].show == true) {
                        children.items[e.target.dataset.index].show = false
                    } else {
                        children.items[e.target.dataset.index].show = true
                    }
                    this.$forceUpdate();


                },
                //收藏
                savetofav: function(e, item) {
                    if (operateStatus == 0) return;
                    operateStatus = 0; //避免狂点
                    var data = {
                        uid: state.userid,
                        message_id: item.id,
                        memberToken: memberToken
                    };
                    if (e.srcElement.getAttribute('src') == '../../images/icon/fav_0.png') {
                        e.srcElement.setAttribute('src', '../../images/icon/fav_1.png');
                        setTimeout(function() {
                            operateStatus = 1;
                        }, 1000);
                    } else {
                        e.srcElement.setAttribute('src', '../../images/icon/fav_0.png');
                        setTimeout(function() {
                            operateStatus = 1;
                        }, 1000);
                    }
                    mui.post(Apiurl+'index/coll', data, function(data) {
                        console.log(JSON.stringify(data));
                        if (data.coll == "1") {
                            item.coll = 1

                            plus.nativeUI.toast('收藏成功', {
                                verticalAlign: 'middle'
                            });
                            console.log(e.target.dataset.index)
                            if (children.items[e.target.dataset.index].show == true) {
                                children.items[e.target.dataset.index].show = false
                            } else {
                                children.items[e.target.dataset.index].show = true
                            }
                            this.$forceUpdate();
                            setTimeout(function() {
                                operateStatus = 1;
                            }, 1000);
                        }
                        if (data.coll == "0") {
                            item.coll = 0

                            plus.nativeUI.toast('取消收藏', {
                                verticalAlign: 'middle'
                            });
                            setTimeout(function() {
                                operateStatus = 1;
                            }, 1000);
                        }
                    }, 'json');
                },
            },

        });
        //子页面删除评论后，主页需要更新
        window.addEventListener('refreshcomment', function(event) {
            var msgid = event.detail.msgid;

            var data = {
                uid: state.userid,
                id: msgid,
                memberToken: memberToken
            };
            mui.post(Apiurl+'index/message_info', data, function(res) {
                if (data.message && data.message.length > 0) {
                    children.forEach(function(item) {
                        res.message.forEach(function(res) {
                            console.log(res)
                            if (item.id == res.id) {
                                item.comment = res.comment;
                            }
                        })
                    });
                }
            }, 'json');
        });
        //刷新评论内容，避免因为消息详情删除评论后，首页没删除
        window.addEventListener('refreshmomentmsg', function(event) {
            pulldownRefresh();
        });
        window.addEventListener('refreshvideo', function(event) {
            children.modelShows = false
            pause();
        });

        window.addEventListener('refreshmomentcoll', function(event) {
            var msgid = event.detail.msgid;
            children.items.forEach(function(item) {
                if (item.id == msgid) {
                    item.coll = 0;
                }
            })
        });
        window.addEventListener('refreshmomentcomment', function(event) {
            var msgid = event.detail.msgid;
            var data = {
                uid: state.userid,
                id: msgid,
                memberToken: memberToken
            };
            mui.post(Apiurl+'index/message_info', data, function(res) {
                console.log(res)
                if (res.message && res.message.length > 0) {
                    children.items.forEach(function(item) {
                        res.message.forEach(function(res) {
                            console.log(res)
                            if (item.id == res.id) {
                                item.comment = res.comment;
                            }
                        })
                    });
                }
            }, 'json');
        });
        //下拉刷新
        function pulldownRefresh(pages) {
            if (window.plus && plus.networkinfo.getCurrentType() === plus.networkinfo.CONNECTION_NONE) {
                plus.nativeUI.toast('似乎已断开与互联网的连接', {
                    verticalAlign: 'top'
                });
                return;
            }
            data.page = pages
                //获取消息列表   
            var newArray = []
            mui.post(Apiurl+'index/message_list_new', data, function(data) {
                console.log(data)
                if (data.message && data.message.length > 0) {
                    newArray = data.message
                    for (var i = 0; i < data.message.length; i++) {
                        console.log(newArray[i].id)
                        newArray[i].show = false
                    }
                    children.items = newArray
                    console.log(JSON.stringify(newArray))
                    console.log(children.items)
                }
                mui('#list').pullRefresh().endPulldownToRefresh();
            }, 'json');
            mui.post(Apiurl+'index/pinglun', data, function(data) {
                children.newmsg = data;
                if (data.count != 0) {
                    document.getElementById('noreadmsg').style.display = 'block';
                } else if (data.count == 0) {
                    document.getElementById('noreadmsg').style.display = 'none';
                }
            }, 'json')
        }
        //上拉加载
        function pullupRefresh(pages) {
            data.page = pages;
            //请求历史列表信息流
            mui.post(Apiurl+'index/message_list_new', data, function(data) {
                if (pages <= data.pagecount) {
                    if (data.message && data.message.length > 0) {
                        children.items = children.items.concat(convert(data.message));
                        console.log(children.items)
                    }
                }
                mui('#list').pullRefresh().endPullupToRefresh();
            }, 'json');

        }
        //打开微信文章详情 
        function open_detail(url, title) {
            mui.openWindow({
                url: url,
                id: 'ad_detail',
                styles: {
                    "render": "always",
                    "popGesture": "hide",
                    "bounce": "vertical",
                    "bounceBackground": "#efeff4",
                    "titleNView": titleNView = { //详情页原生导航配置
                        autoBackButton: true, //自动绘制返回箭头
                        backgroundColor: '#fff', //导航栏背景色
                        titleText: title, //导航栏标题
                        titleColor: '#000', //文字颜色
                        //coverage:"120px",
                        //type: 'transparent', //透明渐变样式
                        splitLine: { //底部分割线
                            color: '#DFDFDF'
                        }
                    }
                }
            });
        }
        /**
         * 1、将服务端返回数据，转换成前端需要的格式
         * 2、若服务端返回格式和前端所需格式相同，则不需要改功能
         * 
         * @param {Array} items 
         */
        function convert(items) {
            var newItems = [];
            items.forEach(function(item) {
                newItems.push({
                    uid: state.userid,
                    id: item.id,
                    member_avatar: item.member_avatar,
                    member_name: item.member_name,
                    member_id: item.member_id,
                    message_image: item.message_image,
                    pic: item.pic,
                    title: item.title,
                    content: item.content,
                    link: item.link,
                    coll: item.coll,
                    type: item.type,
                    ftime: item.ftime,
                    upvote_count: item.upvote_count,
                    upvote: item.upvote,
                    upvote_status: item.upvote_status,
                    comment: item.comment,
                    video: item.video,
                    comment_count: item.comment_count,
                    videoimg: item.videoimg,
                    show: false

                });
            });
            return newItems;
        }
    </script>
</body>

</html>